<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>发送消息</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link href="/oa/css/message.css" type="text/css" rel="stylesheet" />
<link href="/oa/css/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="/oa/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="/oa/js/datePicker/WdatePicker.js"></script>
<script type="text/javascript">
	$(document).ready(
			function(e) {
				//init
				$("#institution").attr("disabled", true);
				$("#branch").attr("disabled", true);
				$("#name").attr("disabled", true);
				$("#radio2").attr("checked", "checked");
				$("#person").hide();

				//text
				$("input:text").eq(1).focus(function(e) {
					this.blur();
				});
				$("input:text").eq(2).focus(function(e) {
					this.blur();
				});

				//radio
				$("#radio1").click(function(e) {
					$("#filter").fadeOut('slow');
				});
				$("#radio2").click(function(e) {
					$("#filter").fadeIn('slow');
				});

				//checkbox
				var checkbox1 = $('input:checkbox(class="check-all")');
				$(checkbox1.eq(0)).click(
						function(e) {
							if ($(this).attr("checked")) {
								checkbox1.eq(2).attr("disabled", true);
								$("#institution").attr("disabled", false);
							} else {
								checkbox1.eq(2).attr("disabled", false);
								$("#institution").attr("disabled", true);
								$("#institution").find("option:first").attr(
										'selected', 'selected');
								$("#person").hide();
							}
						});
				$(checkbox1.eq(1)).bind(
						'click',
						function() {
							if ($(this).attr("checked")) {
								checkbox1.eq(2).attr("disabled", true);
								checkbox1.eq(0).attr("checked", true);
								$("#branch").attr("disabled", false);
								$("#institution").attr("disabled", false);
							} else {
								checkbox1.eq(2).attr("disabled", false);
								checkbox1.eq(0).attr("checked", false);
								$("#branch").attr("disabled", true);
								$("#institution").attr("disabled", true);
								$("#branch").find("option:first").attr(
										'selected', 'selected');
								$("#institution").find("option:first").attr(
										'selected', 'selected');
								$("#person").hide();
							}
						});
				$(checkbox1.eq(2)).click(function(e) {
					if ($(this).attr("checked")) {
						checkbox1.eq(0).attr("disabled", true);
						checkbox1.eq(1).attr("disabled", true);
						$("#name").attr("disabled", false);
					} else {
						checkbox1.eq(0).attr("disabled", false);
						checkbox1.eq(1).attr("disabled", false);
						$("#name").attr("value", '');
						$("#name").attr("disabled", true);
						$("#person").hide();
					}
				});

				//确定选择范围
				$("#scoping").click(
						function(e) {
							var institution = $("#institution");
							var branch = $("#branch");
							var name = $("#name");
							var institutionText = institution.find(
									"option:selected").text();
							var branchText = branch.find("option:selected")
									.text();
							var nameText = name.val();
							var pleaseSelect = "==请选择==";
							if (institution.attr("disabled") == true
									&& branch.attr("disabled") == true
									&& name.attr("disabled") == true) {
								alert("请确定范围！");
							} else {
								if (institution.attr("disabled") == false
										&& institutionText == pleaseSelect) {
									alert("请选择机构！");
									return;
								}
								if (branch.attr("disabled") == false
										&& branchText == pleaseSelect) {
									alert("请选择部门！");
									return;
								}
								if (name.attr("disabled") == false
										&& nameText == "") {
									alert("请输入名字！");
									return;
								}
								$("#person").fadeIn('slow');
							}
						});

				//全选
				$("#checkAll").click(
						function() {
							$("#person :checkbox").attr("checked",
									$("#checkAll").attr("checked"));
						});

			});
				function submitForm() {
					if ($("#title").val() == "") {
						alert("请输入标题！");
						return false;
					}
					if ($("#beginTime").val() == "") {
						alert("请选择开始有效时间！");
						return false;
					}
					if ($("#endTime").val() == "") {
						alert("请选择结束有效时间");
						return false;
					}
					if ($("#content").val() == "") {
						alert("请输入消息内容！");
						return false;
					}
					return true;
				}
</script>
</head>

<body>
	<s:form action="addMessageToUser" namespace="/messageManage" onsubmit="submitForm()">
		<div class="wrap" title="消息填写区">
			<div class="base">
				<table>
					<tr>
						<td><b>消息标题</b>
						</td>
						<td><input type="text" name="messageBean.title" id="title" />
						</td>
					</tr>
					<tr>
						<td>消息类型</td>
						<td><select name="messageType"><option
									value="General">一般消息</option>
								<option value="Urgent">紧急消息</option>
						</select></td>
					</tr>
					<tr>
						<td>开始有效时间</td>
						<td><input type="text" name="messageBean.beginTime" id="beginTime"
							onClick="WdatePicker({dateFmt:'yyyy-MM-dd 00:00:00',minDate: '%y-%M-<%="#"%>{%d+1}'})" />
						</td>
					</tr>
					<tr>
						<td>结束有效时间</td>
						<td><input type="text" name="messageBean.endTime" id="endTime"
							onClick="WdatePicker({dateFmt:'yyyy-MM-dd 23:59:59',minDate: '%y-%M-<%="#"%>{%d+1}'})" />
						</td>
					</tr>
					<tr>
						<td><b>发送对象</b>
						</td>
						<td><input type="radio" name="raido1" title="所有人" id="radio1">所有人<input
							type="radio" name="raido1" id="radio2" title="选择特定对象">选择特定对象
						</td>
					</tr>
				</table>
			</div>
			<!-- Start Content Box -->
			<div class="content-box-header" id="filter">
				<div class="change">
					<b>筛选范围：</b>
					<p>
						<input name="checkbox" type="checkbox" class="check-all" /> 按机构 <input
							name="checkbox1" type="checkbox" class="check-all" /> 按部门 <input
							name="checkbox2" type="checkbox" class="check-all" /> 按姓名
					</p>
					<p>
						机构： <select name="select" id="institution">
							<option value="">==请选择==</option>
							<option value="ckgly">仓库管理员</option>
							<option value="cly">材料员</option>
							<option value="xmjl">项目经理</option>
							<option value="admin">系统管理员</option>
						</select> 部门 <select name="select2" id="branch" onchange="findByRoleName()">
							<option value="">==请选择==</option>
							<option value="ckgly">仓库管理员</option>
							<option value="cly">材料员</option>
							<option value="xmjl">项目经理</option>
							<option value="admin">系统管理员</option>
						</select> 姓名： <input name="name" id="name" type="text" value="" size="20px"
							height="20px" /> （模糊查找） <br /> <br /> <input id="scoping"
							name="submit" type="button" class="button" value="确定选择范围" />
					</p>
				</div>
				<div class="person" id="person">
					<input type="checkbox" id="checkAll" />全选<input type="checkbox"
						value="${id}" name="delIds" />
				</div>
			</div>
			<div class="content">
				<table>
					<tr>
						<td valign="top">消息内容：</td>
						<td><textarea rows="10" cols="100%" name="messageBean.content"
								id="content"></textarea></td>
					</tr>
				</table>
			</div>
			<div>
				<input type="submit" class="button" value="保存消息" id="addMessage"  /> <input
					type="button" class="button" value="返回" onclick="history.go(-1)" />
			</div>
		</div>
	</s:form>
</body>
</html>
